﻿using StockHelper.Scripts;
using StockHelper.Scripts.Comm;
using StockHelper.Scripts.Stock;
using StockHelper.Scripts.Types;
using StockHelper.Style;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Timer = StockHelper.Scripts.Comm.Timer;

namespace StockHelper
{
    public partial class Mine : Form
    {
        public static Mine e;
        private Image itemImage;
        
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;//用双缓冲绘制窗口的所有子控件
                return cp;
            }
        }

        public Mine()
        {
            InitializeComponent();
            e = this;

            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景. 
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
            
        }

        private List<StockItem> stockItems = new List<StockItem>();
        private void OnLoad(object sender, EventArgs e)
        {
            this.BackgroundImage = Assets.LoadImg(Config.Get("bgImage", UI.bgImage));
            itemImage = Assets.LoadImg(UI.main_item);
            this.ui_bottom.BackgroundImage = Assets.LoadImg(UI.main_bottom);
            this.ui_right.BackgroundImage = Assets.LoadImg(UI.main_right);
            this.VoicePlay_Btn.BackgroundImage = Assets.LoadImg(UI.main_语音_btn);
            this.AddStock_Btn.BackgroundImage = Assets.LoadImg(UI.main_新增股票_btn);
            this.TopMostBox_Btn.BackgroundImage = Assets.LoadImg(UI.main_悬浮窗_btn);
            this.EarlyWarning_Btn.BackgroundImage = Assets.LoadImg(UI.main_预警_btn);

            if (!Config.isDebug && !SteamManager.Init()) {
                Quit();
                return;
            }

            var thread = new System.Threading.Thread(()=> {
                System.Threading.Thread.Sleep(100);
                MethodInvoker invoke = new MethodInvoker(Init);
                BeginInvoke(invoke);
            });
            thread.Start();
            
            StockHelper.Scripts.Comm.Timer.Add(Updata, Time.GetTimeStamp() + 3, 3);
            ScrollBar_Init();
        }

        private void Init()
        {
            StockListPlane.Controls.Clear();

            foreach (string key in Config.Get("stockList", new ArrayList()))
            {
                AddStockOnList(key);
            }

        }

        public void Updata()
        {
            if (WindowState == FormWindowState.Minimized)
                return;

            foreach (StockItem item in stockItems)
            {
                item.现价.Text = "现价: " + StockCtrl.GetData(item.key, Param.当前价格);
                item.开盘.Text = "开盘: " + StockCtrl.GetData(item.key, Param.今日开盘价);
                item.昨收.Text = "昨收: " + StockCtrl.GetData(item.key, Param.昨日收盘价);
                item.今高.Text = "今高: " + StockCtrl.GetData(item.key, Param.今日最高价);
                item.今低.Text = "今低: " + StockCtrl.GetData(item.key, Param.今日最低价);
                item.竞买.Text = StockCtrl.GetData(item.key, Param.竞买价).ToString();
                item.成交数.Text = StockCtrl.GetData(item.key, Param.成交数).ToString();
                item.成交额.Text = StockCtrl.GetData(item.key, Param.成交金额).ToString();
                item.买1.Text = "买1: " + StockCtrl.GetData(item.key, Param.买一报价) + "/" + StockCtrl.GetData(item.key, Param.买一股票数);
                item.买2.Text = "买2: " + StockCtrl.GetData(item.key, Param.买二报价) + "/" + StockCtrl.GetData(item.key, Param.买二股票数);
                item.买3.Text = "买3: " + StockCtrl.GetData(item.key, Param.买三报价) + "/" + StockCtrl.GetData(item.key, Param.买三股票数);
                item.买4.Text = "买4: " + StockCtrl.GetData(item.key, Param.买四报价) + "/" + StockCtrl.GetData(item.key, Param.买四股票数);
                item.买5.Text = "买5: " + StockCtrl.GetData(item.key, Param.买五报价) + "/" + StockCtrl.GetData(item.key, Param.买五股票数);
                item.卖1.Text = "卖1: " + StockCtrl.GetData(item.key, Param.卖一报价) + "/" + StockCtrl.GetData(item.key, Param.卖一股票数);
                item.卖2.Text = "卖2: " + StockCtrl.GetData(item.key, Param.卖二报价) + "/" + StockCtrl.GetData(item.key, Param.卖二股票数);
                item.卖3.Text = "卖3: " + StockCtrl.GetData(item.key, Param.卖三报价) + "/" + StockCtrl.GetData(item.key, Param.卖三股票数);
                item.卖4.Text = "卖4: " + StockCtrl.GetData(item.key, Param.卖四报价) + "/" + StockCtrl.GetData(item.key, Param.卖四股票数);
                item.卖5.Text = "卖5: " + StockCtrl.GetData(item.key, Param.卖五报价) + "/" + StockCtrl.GetData(item.key, Param.卖五股票数);
            }
        }

        public void AddStockOnList(string key) {

            StockItem box = new StockItem
            {
                key = key,
                item = new Panel
                {
                    BackColor = Color.Transparent,
                    BackgroundImage = itemImage,
                    Width = 600,
                    Height = 100,
                    Margin = new Padding(10, 10, 10, 10),
                    BackgroundImageLayout = ImageLayout.Zoom,
                    Cursor = Cursors.Hand,
                },
                名称 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    Location = new Point(14, 13),
                    Size = new Size(100, 27),
                    Font = new Font("微软雅黑", 15),
                    ForeColor = Color.White,
                    Text = StockCtrl.GetData(key, Param.名称).ToString(),
                    AutoSize = true,
                },
                code = new ExLabel
                {
                    BackColor = Color.Transparent,
                    Location = new Point(19, 60),
                    Size = new Size(85, 21),
                    Font = new Font("微软雅黑", 12),
                    ForeColor = Color.White,
                    Text = StockCtrl.GetData(key, Param.code).ToString(),
                    AutoSize = true,
                },
                现价 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(133, 13),
                    Size = new Size(104, 27),
                    Font = new Font("微软雅黑", 15),
                    Text = "现价: "+ StockCtrl.GetData(key, Param.当前价格),
                    AutoSize = true,
                },
                开盘 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(130, 54),
                    Size = new Size(51, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "开盘: "+ StockCtrl.GetData(key, Param.今日开盘价),
                    AutoSize = true,
                },
                昨收 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(130, 75),
                    Size = new Size(51, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "昨收: " + StockCtrl.GetData(key, Param.昨日收盘价),
                    AutoSize = true,
                },
                今高 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(192, 54),
                    Size = new Size(51, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "今高: " + StockCtrl.GetData(key, Param.今日最高价),
                    AutoSize = true,
                },
                今低 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(192, 75),
                    Size = new Size(51, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "今低: " + StockCtrl.GetData(key, Param.今日最低价),
                    AutoSize = true,
                },
                竞买 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(266, 36),
                    Size = new Size(32, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = StockCtrl.GetData(key, Param.竞买价).ToString(),
                    AutoSize = true,
                },
                竞卖 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(319, 36),
                    Size = new Size(32, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = StockCtrl.GetData(key, Param.竞卖价).ToString(),
                    AutoSize = true,
                },
                成交数 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(263, 75),
                    Size = new Size(32, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = StockCtrl.GetData(key, Param.成交数).ToString(),
                    AutoSize = true,
                },
                成交额 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(317, 75),
                    Size = new Size(32, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = StockCtrl.GetData(key, Param.成交金额).ToString(),
                    AutoSize = true,
                },
                买1 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(390, 8),
                    Size = new Size(81, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "买1: "+ StockCtrl.GetData(key, Param.买一报价) + "/" + StockCtrl.GetData(key, Param.买一股票数),
                    AutoSize = true,
                },
                买2 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(390, 24),
                    Size = new Size(81, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "买2: "+  StockCtrl.GetData(key, Param.买二报价) + "/" + StockCtrl.GetData(key, Param.买二股票数),
                    AutoSize = true,
                },
                买3 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(390, 40),
                    Size = new Size(81, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "买3: "+ StockCtrl.GetData(key, Param.买三报价) + "/" + StockCtrl.GetData(key, Param.买三股票数),
                    AutoSize = true,
                },
                买4 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(390, 57),
                    Size = new Size(81, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "买4: "+ StockCtrl.GetData(key, Param.买四报价) + "/" + StockCtrl.GetData(key, Param.买四股票数),
                    AutoSize = true,
                },
                买5 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(390, 74),
                    Size = new Size(81, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "买5: "+  StockCtrl.GetData(key, Param.买五报价) + "/" + StockCtrl.GetData(key, Param.买五股票数),
                    AutoSize = true,
                },
                卖1 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(499, 8),
                    Size = new Size(81, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "卖1: " +  StockCtrl.GetData(key, Param.卖一报价) + "/" + StockCtrl.GetData(key, Param.卖一股票数),
                    AutoSize = true,
                },
                卖2 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(499, 24),
                    Size = new Size(81, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "卖2: " +StockCtrl.GetData(key, Param.卖二报价) + "/" + StockCtrl.GetData(key, Param.卖二股票数),
                    AutoSize = true,
                },
                卖3 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(499, 40),
                    Size = new Size(81, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "卖3: " +  StockCtrl.GetData(key, Param.卖三报价) + "/" + StockCtrl.GetData(key, Param.卖三股票数),
                    AutoSize = true,
                },
                卖4 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(499, 57),
                    Size = new Size(81, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "卖4: " +StockCtrl.GetData(key, Param.卖四报价) + "/" + StockCtrl.GetData(key, Param.卖四股票数),
                    AutoSize = true,
                },
                卖5 = new ExLabel
                {
                    BackColor = Color.Transparent,
                    ForeColor = Color.White,
                    Location = new Point(499, 74),
                    Size = new Size(81, 16),
                    Font = new Font("微软雅黑", 8),
                    Text = "卖5: " + StockCtrl.GetData(key, Param.卖五报价) + "/" + StockCtrl.GetData(key, Param.卖五股票数),
                    AutoSize = true,
                },
            };
            box.item.Controls.Add(box.名称);
            box.item.Controls.Add(box.code);
            box.item.Controls.Add(box.现价);
            box.item.Controls.Add(box.开盘);
            box.item.Controls.Add(box.昨收);
            box.item.Controls.Add(box.今高);
            box.item.Controls.Add(box.今低);
            box.item.Controls.Add(box.竞买);
            box.item.Controls.Add(box.竞卖);
            box.item.Controls.Add(box.成交数);
            box.item.Controls.Add(box.成交额);
            box.item.Controls.Add(box.买1);
            box.item.Controls.Add(box.买2);
            box.item.Controls.Add(box.买3);
            box.item.Controls.Add(box.买4);
            box.item.Controls.Add(box.买5);
            box.item.Controls.Add(box.卖1);
            box.item.Controls.Add(box.卖2);
            box.item.Controls.Add(box.卖3);
            box.item.Controls.Add(box.卖4);
            box.item.Controls.Add(box.卖5);
            box.item.Controls.Add(new ExLabel
            {
                BackColor = Color.Transparent,
                ForeColor = Color.White,
                Location = new Point(266, 13),
                Size = new Size(30, 16),
                Font = new Font("微软雅黑", 8),
                Text = "竞买",
                AutoSize = true,
            });
            box.item.Controls.Add(new ExLabel
            {
                BackColor = Color.Transparent,
                ForeColor = Color.White,
                Location = new Point(319, 13),
                Size = new Size(30, 16),
                Font = new Font("微软雅黑", 8),
                Text = "竞卖",
                AutoSize = true,
            });
            box.item.Controls.Add(new ExLabel
            {
                BackColor = Color.Transparent,
                ForeColor = Color.White,
                Location = new Point(266, 54),
                Size = new Size(41, 16),
                Font = new Font("微软雅黑", 8),
                Text = "成交数",
                AutoSize = true,
            });
            box.item.Controls.Add(new ExLabel
            {
                BackColor = Color.Transparent,
                ForeColor = Color.White,
                Location = new Point(319, 54),
                Size = new Size(41, 16),
                Font = new Font("微软雅黑", 8),
                Text = "成交额",
                AutoSize = true,
            });
            stockItems.Add(box);
            box.item.MouseClick += new MouseEventHandler((sender, e) =>
            {
                ClickItem(box);
            });
            this.StockListPlane.Controls.Add(box.item);
        }


        private void Mine_SizeChanged(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                this.StockListPlane.Controls.Clear();
                this.ShowInTaskbar = false;
            }
        }

        private void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (WindowState == FormWindowState.Minimized)
                {
                    //还原窗体显示    
                    WindowState = FormWindowState.Normal;
                    //激活窗体并给予它焦点
                    this.Activate();
                    //任务栏区显示图标
                    this.ShowInTaskbar = true;
                    var thread = new System.Threading.Thread(() => {
                        System.Threading.Thread.Sleep(100);
                        MethodInvoker invoke = new MethodInvoker(Init);
                        BeginInvoke(invoke);
                    });
                    thread.Start();
                }
            }
        }

        private void AddStock_Btn_Click(object sender, EventArgs e)
        {
            new AddStock().Show();
        }

        private void VoicePlay_Btn_Click(object sender, EventArgs e)
        {
            new VoicePlay().Show();
        }

        private void Mine_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.NotifyIcon.Dispose();
            Quit();
        }


        public static void Quit()
        {
            Application.Exit();
            Application.ExitThread();
            Timer.Stop();
        }

        private void TopMostBox_Btn_Click(object sender, EventArgs e)
        {
            Config.Set("topMost/show", "1");
            if (TopMostBox.e == null || TopMostBox.e.IsDisposed)
            {
                new TopMostBox().Show();
            }
            else {
                TopMostBox.e.CloseForm();
            }
        }

        private void EarlyWarning_Btn_Click(object sender, EventArgs e)
        {
            MessageBox.Show("功能开发中");
        }

        private void 悬浮窗ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Config.Set("topMost/show", "1");
            if (TopMostBox.e == null || TopMostBox.e.IsDisposed)
            {
                new TopMostBox().Show();
            }
            else
            {
                TopMostBox.e.CloseForm();
            }
        }

        private void NotifyIconMenu_Opening(object sender, CancelEventArgs e)
        {
            this.悬浮窗ToolStripMenuItem.Checked = TopMostBox.e != null && !TopMostBox.e.IsDisposed;
            this.showToolStripMenuItem.Enabled = WindowState == FormWindowState.Minimized;
            this.语音播报ToolStripMenuItem.Checked = Config.playVoice;
        }

        private void 语音播报ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.语音播报ToolStripMenuItem.Checked = Config.playVoice = !Config.playVoice;
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Quit();
        }


        public class StockItem
        {
            public Panel item;
            public string key;
            public ExLabel code;
            public ExLabel 名称;
            public ExLabel 现价;
            public ExLabel 开盘;
            public ExLabel 昨收;
            public ExLabel 今高;
            public ExLabel 今低;
            public ExLabel 竞买;
            public ExLabel 竞卖;
            public ExLabel 成交数;
            public ExLabel 成交额;
            public ExLabel 买1;
            public ExLabel 买2;
            public ExLabel 买3;
            public ExLabel 买4;
            public ExLabel 买5;
            public ExLabel 卖1;
            public ExLabel 卖2;
            public ExLabel 卖3;
            public ExLabel 卖4;
            public ExLabel 卖5;
        }


        StockItem clickItem;
        private void ClickItem(StockItem e)
        {
            clickItem = e;
            this.ItemMenuStrip.Show(MousePosition);
            int index = -1;
            ArrayList list = Config.Get("stockList", new ArrayList());
            for (int i = 0; i < list.Count; i++)
            {
                if (clickItem.key == list[i].ToString())
                    index = i;
            }
            this.backToolStripMenuItem.Enabled = index != 0;
            this.nextToolStripMenuItem.Enabled = index != list.Count-1;

        }

        private void CopyUrl_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(clickItem.key);
        }

        private void backToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChangeIndex(-1);
        }

        private void nextToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChangeIndex(1);
        }

        private void delToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChangeIndex(0);
        }

        private void ChangeIndex(int change)
        {
            ArrayList list = Config.Get("stockList", new ArrayList());
            int index = -1;
            for (int i=0;i<list.Count;i++ ) {
                if (clickItem.key == list[i].ToString())
                    index = i;
            }
            if (index == -1)
                return;
            else if (change == 0)
            {
                list.RemoveAt(index);
                this.StockListPlane.Controls.RemoveAt(index);
                StockData stock = StockCtrl.stockData[clickItem.key];
                ArrayList _list = Config.Get("voicePlay", new ArrayList());
                for (int i = list.Count-1; i >= 0; i--) {
                    Hashtable data = _list[i] as Hashtable;
                    if (data.ContainsKey("url") && data["url"].ToString().IndexOf(stock.code) > -1) {
                        _list.RemoveAt(i);
                    }
                }
                StockCtrl.stockData.Remove(clickItem.key);
            }
            else
            {
                var obj = list[index];
                list[index] = list[index + change];
                list[index + change] = obj;
                this.StockListPlane.Controls.SetChildIndex(clickItem.item,  index + change);
            }
            Config.Save();
        }




        private void ScrollBar_Init()
        {
            if (this.StockListPlane.Height <= this.StockListPlaneBox.Height)
            {
                this.ScrollBar.Visible = false;
                return;
            }
            this.ScrollBar.Visible = true;
            //滑块高度=可视高度/实际高度*滚动条高度（pn_scroll.Height）
            float length = (float)this.StockListPlaneBox.Height / (float)this.StockListPlane.Height * (float)this.ScrollBar.Height;
            this.ScrollBar.SliderHeight = (int)length;

            this.ScrollBar.MouseDown += ScrollBar_MouseDown;
            this.ScrollBar.MouseUp += ScrollBar_MouseUp;
            this.ScrollBar.ValueChanged += ScrollBar_ValueChanged;  //滚动条拖动事件
            this.ScrollBar.GotFocus += ScrollBar_GotFocus;  //滚动条获得焦点事件
            this.StockListPlane.MouseWheel += ScrollBar_MouseWheel; //pn_info添加滚轮事件
        }
        bool isMouseWheel = false; //防止滚轮带动的滚动条再次触发sb_ValueChanged
        //pn_info滚轮事件
        private void ScrollBar_MouseWheel(object sender, MouseEventArgs e)
        {
            isMouseWheel = true;
            int scrollRang = 40; //每次滚动高度(px)
            int sbRang = calSbRang(scrollRang); //滚动条实际滚动幅度
            if (e.Delta > 0) //滚轮向上
            {
                if (this.ScrollBar.Value - sbRang <= 0)
                {
                    //滚动到顶，直接设为默认值，防止滚动产生的误差
                    this.ScrollBar.Value = 0;
                    this.StockListPlane.Top = 0;
                }
                else
                {
                    this.ScrollBar.Value -= sbRang;
                    this.StockListPlane.Top += scrollRang;
                }
            }
            else//滚轮向下
            {
                if (this.ScrollBar.Value + sbRang >= 100)
                {
                    //滚动到底，直接设为默认值，防止滚动产生的误差
                    this.ScrollBar.Value = 100;
                    this.StockListPlane.Top = -(this.StockListPlane.Height - this.StockListPlaneBox.Height);
                }
                else
                {
                    this.ScrollBar.Value += sbRang;
                    this.StockListPlane.Top -= scrollRang;
                }
            }
        }
        //因为滚动条滚动幅度可能是小数，转int后会损失精度，导致滚动到底或到底时产生一定误差
        float residue = 0; //float转int后舍去的小数部分累积凑1
        private int calSbRang(int scrollRang)
        {
            float temp = ((float)scrollRang) / (float)(this.StockListPlane.Height - this.StockListPlaneBox.Height) * 100;//滚动条滚动比例
            int sbRang = Convert.ToInt32(temp);//保留整数部分
            residue += temp - (float)sbRang; //累积舍去的小数部分
            if (residue >= 1)
            {
                residue -= 1;
                sbRang += 1;
            }
            return sbRang;
        }

        //滚动条获取焦点时把焦点给pn_info,防止触发滚动条的滚轮事件(滚动条的滚轮滑动和容器内的滑动速度不一致)
        private void ScrollBar_GotFocus(object sender, EventArgs e)
        {
            isMouseWheel = false;
            this.StockListPlane.Focus();
        }

        //滚动条拖动
        private void ScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (!isMouseWheel)
                this.StockListPlane.Top = -Convert.ToInt32((float)this.ScrollBar.Value / 100 * (float)(this.StockListPlane.Height - this.StockListPlaneBox.Height));
        }

        private void ScrollBar_MouseDown(object sender, MouseEventArgs e)
        {
            this.StockListPlaneBox.BackColor = Color.Silver;
        }
        private void ScrollBar_MouseUp(object sender, MouseEventArgs e)
        {
            this.StockListPlaneBox.BackColor = Color.Transparent;
        }


    }
}
